/******************************************************************************
BonusBingoGuts.h: interface for the BonusBingoGuts class.

  Copyright 2005 Realtime Gaming.  All rights reserved.
******************************************************************************/
#if !defined(_BONUSBINGOGUTS_H_)
#define _BONUSBINGOGUTS_H_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "GameGuts.h"

#ifdef DEBUG_KNOWNSPINS
#include "BonusBingoConstants.h"
#endif

class BonusBingoGame;
class BonusBingoGameResult;
class BonusBingoSubGame;
class BonusBingoSQL;

class BonusBingoGuts  : public GameGuts
{
    typedef GameGuts super;

public:
	BonusBingoGuts(GameConnection*);
	virtual ~BonusBingoGuts();

public:     //Overridden Virtuals
    uint8   getGameID() const { return 20; };
    uint8   getMachineID() const { return 0; };
    int32   getMinBet() const;
    int32   getMaxBet() const;
    uint8   getMaxCards() const;
    uint8   getMaxGames() const;

    void    processBet(uint8* buf, 
                       int32 len, int32 num_cards, 
                       int32 num_games);

    int32   getPlayerLimits(const PID& pid, int32* compFactor);
	int32	getDenominations();

    bool8   getSavedGame();

    void    sendSavedGame();

    bool8   allowsMultipliers() const;    

    bool8   hasSubGame() const;
    
    uint8   getPaytable() const;
	int32	getDenomValue(int32 index) const;

    void    processMultiplierResponse(uint8* msgbuf, int32 nMsgLen);

	void	processSubGameMessage();

protected:    
    bool8   playCurrentGame(int32 balance);

    int32   getSubGameRounds();

    void    sendSubGameMessage();
    
    bool8   trackNewGame(BonusBingoGame *game, int32 *Balance) const;

    bool8   trackGameDone(int32 BalAdjust, int32* Balance, 
              BonusBingoGameResult *results) const;
    
    bool8   trackGetSubGame(BonusBingoSubGame*& subgame) const;

    bool8   trackUpdateSubGame( BonusBingoSubGame* subgame ) const;
    
    void    sendResultsMessage(const BonusBingoGameResult& result);

    void    sendGameResult(const BonusBingoGameResult& result);

    void    sendGameData();

    void    sendSubGame();

    void    gameDone();

protected:      //Data    
    static const uint8 MaxGames;
    static const uint8 MaxCards;
    int32 MinBet;
    int32 MaxBet;

    BonusBingoGame*     m_game;
    BonusBingoSubGame*  m_subGame;
	BonusBingoSQL*		m_tracker;
    BonusBingoGameResult*   m_gameResult;

    #ifdef DEBUG_KNOWNSPINS       

public:
    enum
    {
        CARD_0,
        CARD_1,
        CARD_2,
        CARD_3,
        MULTIPLIER,
        JOKER_VALUE,
        KEY_COUNT,
        SUBGAME = KEY_COUNT,
        BONUS_GAME_COUNT = SUBGAME,
        BONUS_GAME_DIE_VALUES = SUBGAME,
        DIE1 = BONUS_GAME_DIE_VALUES,
        DIE2,
        DIE3,
        DIE4,
        DIE5,
    };
    
    static const int32 Random;
    static const int32 Loser;

protected:
	typedef	void (BonusBingoGuts::*DEBUG_SPIN_PROC)();
	static DEBUG_SPIN_PROC g_FunctionTable[];

    void   clearSubGameData();
    void   setupForSubGame();

    static const int32 DataSet1[][KEY_COUNT];
    static const int32 DataSet2[][KEY_COUNT];
    static const int32 DataSet3[][KEY_COUNT];
    static const int32 DataSet4[][KEY_COUNT];
    static const int32 DataSet5[][KEY_COUNT];
    static const int32 DataSet6[][KEY_COUNT];

    static const int32 DATASET_END[KEY_COUNT];

    static const int32 s_CurrentDataSet;

    static int32 s_CurrentOutcome;

    static const int32* s_DataSets[];

    enum CustomHitMasks
    {
        L2_CONTIGUOUS,
        L3_CONTIGUOUS,
        L4_CONTIGUOUS,
        L2_NONCONTIGUOUS,
        L3_NONCONTIGUOUS,
        L4_NONCONTIGUOUS,
        NEAR_MISS_SLASH,
        NEAR_MISS_BACKSLASH,
        NEAR_MISS_CORNERS,
        NEAR_MISS_CROSS,
        NEAR_MISS_T,
        NEAR_MISS_PERIMETER,
        NEAR_MISS_BINGO,
        NEAR_MISS_2L,
        NEAR_MISS_3L,
        NEAR_MISS_4L,
        BLACK_OUT,
        VERT_2_LINES,
        VERT_3_LINES,
        VERT_4_LINES,
        CUSTOM_COUNT,

        DEBUG_FUNCTION = CUSTOM_COUNT,
        RESET_SUBGAME = DEBUG_FUNCTION,
        SETUP_SUBGAME
    };

    static const BonusBingo::HitMask CustomMasks[CUSTOM_COUNT];

public:
    static int32 GetOutcomeValue( int32 key );

    static int32 GetSubgameOutcomeValue( int32 key );

    int32 NextOutcomeValue();
#endif
};

#endif // !defined(_BONUSBINGOGUTS_H_)
